package com.sgb.kjwl.view.widget;

import android.content.Context;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.sgb.kjwl.R;
import com.swgk.core.view.entity.MenuEntity;
import com.swgk.core.view.adapter.CategoryLeftAdapter3;
import com.swgk.core.view.adapter.CategoryRightAdapter3;
import com.swgk.core.dialog.BasePopWindow;
import com.swgk.core.dialog.PopViewHolder;
import com.swgk.core.recyclerview.decoration.RecyclerCustomDecoration;
import com.swgk.core.xrecyclerview.XRecyclerView;

import java.util.List;

public class CategoryPopWindow extends BasePopWindow {
    private RecyclerView leftRecyclerView;
    private XRecyclerView rightRecyclerView;
    private CategoryLeftAdapter3 leftAdapter;
    private CategoryRightAdapter3 rightAdapter;
    private TextView tvCancel;
    private TextView tvOk;

    public CategoryPopWindow(Context context) {
        super(context);
    }

    @Override
    protected int popLayout() {
        return R.layout.popwindow_category;
    }

    @Override
    protected void initView(PopViewHolder holder) {
        leftRecyclerView = holder.getPop().findViewById(R.id.left_recycler);
        rightRecyclerView = holder.getPop().findViewById(R.id.right_recycler);
        tvCancel = holder.getPop().findViewById(R.id.tv_cancel);
        tvOk = holder.getPop().findViewById(R.id.tv_ok);

        if (leftAdapter == null) {
            leftAdapter = new CategoryLeftAdapter3(mContext, null);
        }
        leftRecyclerView.setLayoutManager(new GridLayoutManager(mContext, 1));
        leftRecyclerView.setAdapter(leftAdapter);
        leftRecyclerView.addItemDecoration(new RecyclerCustomDecoration(0,
                0,
                0,
                mContext.getResources().getDimension(R.dimen.dp1), mContext.getResources().getColor(R.color.color_line)));
        leftAdapter.setItemSelect(true);
//        leftAdapter.setOnItemClick(new AdapterOnItemClick<MenuEntity<MenuEntity<MenuEntity>>>() {
//            @Override
//            public void onItemClick(MenuEntity<MenuEntity<MenuEntity>> menuEntityMenuEntity, int position) {
//                rightAdapter.setData(menuEntityMenuEntity.getDatas());
//            }
//        });
        if (rightAdapter == null) {
            rightAdapter = new CategoryRightAdapter3(mContext, null);
        }
        rightRecyclerView.setSectionedRecyclerViewAdapter(rightAdapter);
        rightRecyclerView.setLoadingMoreEnabled(false);
        rightRecyclerView.setPullRefreshEnabled(false);
        GridLayoutManager rightManager = new GridLayoutManager(mContext, 2);
        rightRecyclerView.setLayoutManager(rightManager);
        rightRecyclerView.setAdapter(rightAdapter);

//        rightAdapter.setOnItemClickListener(new SectionAdapterOnItemClick<MenuEntity>() {
//            @Override
//            public void onItemClick(MenuEntity menuEntity, int section, int position) {
//                MToast.showToast(mContext,menuEntity.getName()+"------"+menuEntity.getId());
//                //MaterialListActivity.start(getActivity(), menuEntity.getName(), menuEntity.getId());
//                menuEntity.setSelected(true);
//            }
//        });

        tvCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dismiss();
            }
        });
    }

    public void setDatas(List<MenuEntity<MenuEntity<MenuEntity>>> datas) {
     //   leftAdapter.setDatas(datas);
        rightAdapter.setData(datas.get(0).getDatas());
    }
}
